/*
 * This module deals with the game's internal representation of the map
 * at ingame time. A Map is constructed by the dungeon module from a
 * Layout object. In addition to the general dungeon architecture, the
 * map keeps track of tile graphics, door tiles, triggers and other tile
 * elements which are required to implement everything in the dungeon.
 * Actors and map objects (such as sokoban boxes) are also kept by the Map.
 * The map is not static world information! It may change during the game.
 */

#ifndef MAP_H_
#define MAP_H_

#include "map_object.h"
#include "actor.h"
#include "tile.h"
#include "main.h"
#include "util/direction.h"
#include "util/carray.h"

#define MAX_SPAWNPOINTS MAX_PLAYERS

/*
 * Rule of thumb: Everything that scrolls with the camera belongs in the map.
 */
typedef struct {
	Tile* tile;                    // usage: TILE(map,x,y,z) or TILEC(map,coord)
	int width, height, layers;     // map dimensions
	
	CArray object;                 // pool of MapObjects
	CArray actor;                  // pool of Actors
	
	Coord spawn [MAX_SPAWNPOINTS]; // player starting tiles
	int n_spawns;
} Map;

void map_init (Map* map, int width, int height, int layers);
void map_cleanup (Map* map); // Free resources

/*
 * Adds a new spawn point to the map and returns its index.
 * Returns -1 if the spawn point could not be inserted.
 */
int map_add_spawn (Map* map, Coord coord);

/*
 * Adds uninitialized object
 */
MapObject* map_add_object (Map* map, Coord coord);

/*
 * Returns the object with the given index
 */
MapObject* map_get_object (Map* map, int index);

/*
 * Adds a character to the map. Uses the spawn point with the given index.
 */
Actor* map_spawn_character (Map* map, int spawn, int hp, CharacterType type);

/*
 * Adds a monster to the map.
 */
Actor* map_spawn_monster (Map* map, Coord coord, int hp,
                          MonsterType species, int weapon, int armor);

/*
 * Returns the actor with the given id
 */
Actor* map_get_actor (Map* map, int id);

/* TODO: map_add_effect */

#endif /* MAP_H_ */
